﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Logger.Core
{
    public class LoggerFactory
    {
        #region Singleton & 如果Logger有多种实现时,需要使用Singleton模式

        static string className
        {
            get
            {
                if (System.Configuration.ConfigurationManager.AppSettings["LoggerType"] == null)
                    throw new ArgumentException("请在config文件中配置LoggerType节点,值为Log4Logger或NormalLogger");

                return System.Configuration.ConfigurationManager.AppSettings["LoggerType"].ToString();
            }
        }

        static ILogger _instance
        {
            get
            {
                return (ILogger)Assembly.Load("Logger.Core").CreateInstance("Logger.Core." + className.Trim());
            }
        }

        /// <summary>
        /// Get singleton instance of IoCFactory
        /// </summary>
        public static ILogger Instance
        {
            get
            {
                return _instance;
            }
        }

        #endregion
    }
}
